﻿using System.Windows;
using System.Windows.Input;
using ImageAppViewModels;
using System.Windows.Data;
using Stats.Plugin;
using WpfImageDuplicates;

namespace Stats.Plugin
{
    /// <summary>
    /// Interaction logic for StatsWindow.xaml
    /// </summary>
    public partial class StatsWindow : Window
    {
        public static readonly DependencyProperty FileImageCollectionStatsViewModelProperty =
           DependencyProperty.Register("FileImageCollectionStatsViewModel", typeof(FileImageCollectionStatsViewModel), typeof(StatsWindow), new PropertyMetadata(null, OnFileImageCollectionStatsViewModelPropertyChanged));

        public static readonly DependencyProperty ThumbnailCollectionStatsViewModelProperty =
         DependencyProperty.Register("ThumbnailCollectionStatsViewModel", typeof(ThumbnailCollectionStatsViewModel), typeof(StatsWindow), new PropertyMetadata(null, OnThumbnailCollectionStatsViewModelPropertyChanged));

        public FileImageCollectionStatsViewModel FileImageCollectionStatsViewModel
        {
            get { return (FileImageCollectionStatsViewModel)GetValue(FileImageCollectionStatsViewModelProperty); }
            set { SetValue(FileImageCollectionStatsViewModelProperty, value); }
        }

        public ThumbnailCollectionStatsViewModel ThumbnailCollectionStatsViewModel
        {
            get { return (ThumbnailCollectionStatsViewModel)GetValue(ThumbnailCollectionStatsViewModelProperty); }
            set { SetValue(ThumbnailCollectionStatsViewModelProperty, value); }
        }


        private static void OnFileImageCollectionStatsViewModelPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            StatsWindow source = d as StatsWindow;
            source.UpdateFileImageCollectionStatsViewModel(e.NewValue as FileImageCollectionStatsViewModel);
        }

        private void UpdateFileImageCollectionStatsViewModel(FileImageCollectionStatsViewModel ViewStats)
        {                        
        }
     
        private static void OnThumbnailCollectionStatsViewModelPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            StatsWindow source = d as StatsWindow;
            source.UpdateThumbnailCollectionStatsViewModel(e.NewValue as ThumbnailCollectionStatsViewModel);
        }

        private void UpdateThumbnailCollectionStatsViewModel(ThumbnailCollectionStatsViewModel ViewStats)
        {
        }

        void ThumbnailCollectionStatsViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
        }

        public StatsWindow()
        {
            InitializeComponent();
        }

        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Escape)
            {
                this.Close();
                e.Handled = true;
            }
        }

        private void statsWindow_Loaded(object sender, RoutedEventArgs e)
        {
            Binding b = new Binding() { Mode = BindingMode.OneWay, Source = ThumbnailCollectionStatsViewModel, UpdateSourceTrigger = System.Windows.Data.UpdateSourceTrigger.PropertyChanged };
            thumbStatsView.SetBinding(ThumbnailCollectionStatsView.ThumbnailCollectionStatsViewModelProperty, b);


            Binding b2 = new Binding() { Mode = BindingMode.OneWay, Source = FileImageCollectionStatsViewModel, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged };
            statsView.SetBinding(FileCollectionStatsView.FileImageCollectionStatsViewModelProperty, b2);
        }


        private void btnTopmost_Checked(object sender, RoutedEventArgs e)
        {
            MakeTopmost();
        }

        public void MakeTopmost()
        {
            btnTopmost.IsChecked = true;
            this.Topmost = true;
            this.BringIntoView();
            this.Focus();
            this.Activate();
        }

        private void btnTopmost_Unchecked(object sender, RoutedEventArgs e)
        {
            PushToBack();
        }

        public void PushToBack()
        {
            btnTopmost.IsChecked = false;
            this.Topmost = false;            
        }

    }
}
